import http from '../../utils/request/request'

// 获取数据（分类）
export function getAllInfoByData(page, size, data) {
    return http({
        url: `/breed/farming-work/option/${page}/${size}`,
        method: 'get',
        params: {
            baseName: data.baseName,
            operateName: data.operateName,
            overTime: data.overTime,
            startTime: data.startTime,
        }
    })
}

// 根据关键词搜索养殖作业
export function searchOperationsKeyword(page, size, keyword) {
    return http({
        url: `/breed/farming-work/keyword/${page}/${size}`,
        method: 'get',
        params: { keyword: keyword}
    })
}

// 创建养殖作业
export function newOperation(data) {
    return http({
        url: `/breed/farming-work`,
        method: 'post',
        data: data
    })
}

// 编辑养殖作业
export function editOperation(data) {
    return http({
        url: `/breed/farming-work`,
        method: 'put',
        data: data
    })
}

// 删除多个养殖作业
export function delOperations(ids) {
    return http({
        url: `/breed/farming-work/batch`,
        method: 'delete',
        data: ids
    })
}
// 养殖作业获取养殖档案Id
export function operationGetFarmingId() {
    return http({
        url: `/breed/farming-work/map`,
        method: 'get',
    })
}
// 删除单个养殖作业
export function delOneOperation(id) {
    return http({
        url: `/breed/farming-work/${id}`,
        method: 'delete',
    })
}

// excel导入养殖作业
export function excelPutinOperations(file) {
    return http({
        url: `/breed/farming-work/excel`,
        method: 'post',
        data: file
    })
}

// excel导出养殖作业
export function excelPutoutOperations(fileName) {
    return http({
        url: `/breed/farming-work/${fileName}`,
        method: 'post'
    })
}

// 用户投入品管理
// 查询所有的投入品
export function getSupplyAll() {
    return http({
        url: `/breed/user/supply/all`,
        method: 'get'
    })
}
// 消耗投入品
export function consumeSupply(id, amount) {
    return http({
        url: `/breed/user/supply/consume`,
        method: 'put',
        data: {
            id: id,
            amount: amount
        }
    })
}

export function getColumns() {
    return [ // 表头
          {
            name: "操作名称",
            show: true,
            prop: "operateName"
          },
          {
            name: "操作时间",
            show: true,
            prop: "operateTime"
          },
          {
            name: "所属养殖档案编号",
            show: false,
            prop: "farmingId"
          },
          {
            name: "投入品名称",
            show: true,
            prop: "supplyName"
          },
          {
            name: "基地",
            show: true,
            prop: "baseName"
          },
          {
            name: "投入品所属仓库",
            show: true,
            prop: "warehouseName"
          },
          
          {
            name: "产品SKU",
            show: false,
            prop: "skuNumber"
          },
          {
            name: "投入品SKU",
            show: true,
            prop: "supplySkuNumber"
          },
          {
            name: "投入数量",
            show: true,
            prop: "supplyAmount"
          },
          {
            name: "投入品规格",
            show: true,
            prop: "specification"
          },
          {
            name: "作业编号",
            show: false,
            prop: "id"
          },
          {
            name: "操作人",
            show: true,
            prop: "operator"
          },
          {
            name: "投入品供应商",
            show: true,
            prop: "supplier"
          },
          
          {
            name: "图片",
            show: false,
            prop: "picture"
          },
          {
            name: "操作",
            show: true,
          },
        ]
}

// 格式化时间
export function formatDateToDialog(a) {
        if (!a) {
          return ''
        }
        let dt = new Date(a)
        let s = dt.getSeconds();
        let h = dt.getHours();
        let m = dt.getMinutes();
        let Y = dt.getFullYear();
        let M = dt.getMonth() + 1;
        let D = dt.getDate();
        if (s < 10) {
          s = '0' + s;
        }
        if (h < 10) {
          h = '0' + h;
        }
        if (m < 10) {
          m = '0' + m;
        }
        if (M < 10) {
          M = '0' + M;
        }
        if (D < 10) {
          D = '0' + D;
        }
        return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s
      }


